home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / multiuser / src / library / monitor.c < prev    next >
C/C++ Source or Header  |  1994-06-29  |  3KB  |  133 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Monitoring                                                                *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/semaphores.h>
  12. #include <exec/execbase.h>
  13. #include <proto/exec.h>
  14. #include <string.h>
  15.  
  16. #include "Memory.h"
  17. #include "Monitor.h"
  18. #include "Config.h"
  19. #include "Locale.h"
  20. #include "LibHeader.h"
  21. #include "Task.h"
  22. #include "UserInfo.h"
  23.  
  24.  
  25.     /*
  26.      *        Init Monitor List
  27.      */
  28.  
  29. void InitMonList(void)
  30. {
  31.     ObtainSemaphore(&muBase->MonitorSem);
  32.     NewList((struct List *)&muBase->MonitorList);
  33.     ReleaseSemaphore(&muBase->MonitorSem);
  34. }
  35.  
  36.     /*
  37.      *        Add a Monitor
  38.      *
  39.      *        Public Library Function
  40.      *
  41.      *        This routine may be called only by root
  42.      */
  43.  
  44. BOOL __asm __saveds muAddMonitor(register __a0 struct muMonitor *monitor)
  45. {
  46.     struct muExtOwner *xowner;
  47.     BOOL res = FALSE;
  48.  
  49.     if (monitor) {
  50.         xowner = GetTaskExtOwner(SysBase->ThisTask);
  51.         if (muGetRelationshipA(xowner, NULL, NULL) & muRelF_ROOT_UID) {
  52.             ObtainSemaphore(&muBase->MonitorSem);
  53.             AddTail((struct List *)&muBase->MonitorList, (struct Node *)&monitor->Node);
  54.             ReleaseSemaphore(&muBase->MonitorSem);
  55.             res = TRUE;
  56.         }
  57.         muFreeExtOwner(xowner);
  58.     }
  59.     return(res);
  60. }
  61.  
  62.  
  63.     /*
  64.      *        Remove a Monitor
  65.      *
  66.      *        Public Library Function
  67.      */
  68.  
  69. void __asm __saveds muRemMonitor(register __a0 struct muMonitor *monitor)
  70. {
  71.     struct muMonMsg *msg;
  72.  
  73.     if (monitor) {
  74.         ObtainSemaphore(&muBase->MonitorSem);
  75.         Remove((struct Node *)&monitor->Node);
  76.         if (monitor->Mode == muMon_SEND_MESSAGE)
  77.             while (msg = (struct muMonMsg *)GetMsg(monitor->Message.Port))
  78.                 ReplyMsg(msg);
  79.         ReleaseSemaphore(&muBase->MonitorSem);
  80.     }
  81. }
  82.  
  83.  
  84.     /*
  85.      *        Call the Monitors
  86.      */
  87.  
  88. void CallMonitors(ULONG triggerbit, UWORD from, UWORD to, char *userid)
  89. {
  90.     struct muMonitor *mon;
  91.     struct muMonMsg *msg;
  92.  
  93.     ObtainSemaphoreShared(&muBase->MonitorSem);
  94.     for (mon = (struct muMonitor *)muBase->MonitorList.mlh_Head; mon->Node.mln_Succ;
  95.           mon = (struct muMonitor *)mon->Node.mln_Succ)
  96.         if (mon->Triggers & 1<<triggerbit)
  97.             switch (mon->Mode) {
  98.                 case muMon_SEND_SIGNAL:
  99.                     Signal(mon->Signal.Task, 1<<mon->Signal.SignalNum);
  100.                     break;
  101.                 
  102.                 case muMon_SEND_MESSAGE:
  103.                     if (msg = MAlloc(sizeof(struct muMonMsg))) {
  104.                         msg->ExecMsg.mn_ReplyPort = muBase->MonitorPort;
  105.                         msg->ExecMsg.mn_Length = sizeof(struct muMonMsg);
  106.                         msg->Monitor = mon;
  107.                         msg->Trigger = 1<<triggerbit;
  108.                         msg->From = from;
  109.                         msg->To = to;
  110.                         if (userid) {
  111.                             strncpy(msg->UserID, userid, muUSERIDSIZE-1);
  112.                             msg->UserID[muUSERIDSIZE-1] = '\0';
  113.                         }
  114.                         PutMsg(mon->Message.Port, msg);
  115.                     }
  116.                     break;
  117.             }
  118.     ReleaseSemaphore(&muBase->MonitorSem);
  119. }
  120.  
  121.  
  122.     /*
  123.      *        Free the replied Monitor Messages
  124.      */
  125.  
  126. void FreeRepliedMonMsg(void)
  127. {
  128.     struct muMonMsg *msg;
  129.  
  130.     while (msg = (struct muMonMsg *)GetMsg(muBase->MonitorPort))
  131.         Free(msg, sizeof(struct muMonMsg));
  132. }
  133.